#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>

using namespace std;
bool haha(int rer){
    if (rer <= 1) return false;
    for(int i = 2; i*i <= rer; i++){
        if(rer % i==0)return false;
    }
    return true;
}
int tuc(const string& heh1, const string& heh2, const string& heh3){
    vector<string>sad ={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    int okko1 = find(sad.begin(), sad.end(), heh1)-sad.begin();
    int okko2 = find(sad.begin(), sad.end(), heh2)-sad.begin();
    int okko3 = find(sad.begin(), sad.end(), heh3)-sad.begin();
    return okko1*100+okko2*10+okko3;
}
int main()
{
    string geg, heh1, heh2, heh3;
    getline(cin, geg);
    istringstream s(geg);
    s>>heh1>>heh2>>heh3;
    
    if (heh1 == "zero" || heh2 =="zero" || heh3 == "zero"){
        cout<<"Wrong input"<<endl;
        return 1;
    }
    int rer=tuc(heh1, heh2, heh3);
    if(rer <100||rer>999){
     cout<<"Wrong input"<<endl;
     return 1;
    }
    int yuy=rer, ioi=rer;
    while(true){
        if(haha(yuy)){
            cout<<yuy<<endl;
            return 0;
        }
        if (haha(ioi)){
            cout<<ioi<<endl;
            return 0;
        }
        yuy--;
        ioi++;
    }
    return 0;
}
